#include <iostream>
using std::cout;
using std::endl;

//复数
class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + " << _image << "i" << endl;
    }

    Complex & operator+=(const Complex & rhs){
        _real += rhs._real;
        _image += rhs._image;
        return *this;
    }

    friend
    Complex operator+(const Complex & lhs,const Complex & rhs);
private:
    int _real;
    int _image;
};

Complex operator+(const Complex & lhs,const Complex & rhs){
    return Complex(lhs._real + rhs._real, lhs._image + rhs._image);
}

void test0(){
    int a = 1,b = 2;
    cout << a + b << endl;

    Complex cx(1,2);
    Complex cx2(3,4);


    //Complex cx3 = operator+(cx,cx2) //本质;
    Complex cx3 = cx + cx2;
    cx3.print();
}

void test1(){
    int a = 2;
    int b = 4;
    cout << &a << endl;
    cout << &(a += b) << endl;
    cout << a << endl;
    cout << b << endl;
}

void test2(){
    Complex cx1(3,8);
    Complex cx2(6,4);
    cx1 += cx2;
    /* cx1.operator+=(cx2);//本质 */
    cx1.print();
}

int main(void){
    test2();
    return 0;
}
